import Vue from 'vue'
import Router from 'vue-router'
import Login from '@/components/Login'
import Home from '@/components/Home'
import Welcome from '@/components/Welcome'
import User from '@/components/user/User'
import Authority from '@/components/user/Authority'
import Rights from '@/components/powers/Rights'
import Roles from '@/components/powers/Roles'
import Cate from '@/components/goods/Cate'
import Params from '@/components/goods/params'
import Goods from '@/components/goods/list'
import Add from '@/components/goods/Adds'

Vue.use(Router)

const router = new Router({
  routes: [
    {
      // 路由重定向 
      path: '/',
      redirect: '/Login'
    },
    {
      path: '/Login',
      name: 'Login',
      component: Login
    },
    {
      path: '/Authority',
      name: 'Authority',
      component: Authority
    },
    
    
    {
      path: '/Home',
      name: 'Home',
      component: Home,
      redirect:'/Welcome',
      children: [
        {
          path: '/Welcome',
          name: 'Welcome',
          component: Welcome,
        },
        {
          path: '/users',
          name: 'User',
          component: User
        },
        {
          path: '/rights',
          name: 'Rights',
          component: Rights
        },
        {
          path: '/roles',
          name: 'Roles',
          component: Roles
        },
        {
          path: '/categories',
          name: 'Cate',
          component: Cate
        },
        {
          path: '/params',
          name: 'params',
          component: Params
        },
        {
          path: '/goods',
          name: 'goods',
          component: Goods,
        },
        {
          path: '/goods/add',
          name: 'add',
          component: Add
        },
      
        
      ]
    },
    

  ]
})

// 挂载一个路由导航守卫 to从哪来 from到哪去 next()放行 next（‘/login’）强制跳转
// router.beforeEach((to, from, next) => {
//   if (to.path === "/login") return next();
//   // 获取token
//   const tonkenStr = window.sessionStorage.getItem('token');
//   if (!tonkenStr) return next('/login');
//   next();
// })

export default router;